package com.zy.cat.common.utils;

import java.util.Locale;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取系统信息
 * @author Link
 * @date 2019-03-18 17:11
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {
 
 
    private static ApplicationContext context = null;
 
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        SpringContextUtil.context = applicationContext;
    }
 
    // 国际化使用
    public static String getMessage(String key) {
        return context.getMessage(key, null, Locale.getDefault());
    }
 
    // 获取当前环境
    public static String getActiveProfile() {
        return context.getEnvironment().getActiveProfiles()[0];
    }
    
  // 获取当前是否是生产环境
    public static boolean isProd() {
        return "prod".equals(context.getEnvironment().getActiveProfiles()[0]);
//    	return true;
    }
    
    // 获取当前是否是开发环境
    public static boolean isDev() {
       return "dev".equals(context.getEnvironment().getActiveProfiles()[0]);
    }
}

